/*
 * Ventana.java
 *
 * Created on 25 de marzo de 2008, 14:48
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package mvc.wiew;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;

/**
 *
 * @author notebook
 */
public class Ventana extends JFrame implements WindowListener {
    
    /** Creates a new instance of Ventana */
    private Ventana(String titulo) {
        Dimension p=Toolkit.getDefaultToolkit().getScreenSize();
        ini(titulo,(int)(p.getWidth()*.9), (int)(p.getHeight()*.9));
    }
    private Ventana (String titulo, int ancho, int alto) {
        ini(titulo, ancho, alto);
    }
    
    private void ini(String titulo, int ancho, int alto){
        setTitle(titulo);
        setContentPane(new JDesktopPane());
        getContentPane().setLayout(null);
        Dimension p=Toolkit.getDefaultToolkit().getScreenSize();
        this.setSize(ancho, alto);
        setLocation((int)((p.getWidth()-getWidth())/2),(int)((p.getHeight()-getHeight())/2));
        this.addWindowListener(this);
        this.setVisible(true);
        
    }
    
    public void add(Container c){
        try{
            JComponent cm=(JComponent) this.getContentPane().getComponent(this.getContentPane().getComponentCount()-1);
            c.setLocation((int)(c.getLocation().getX()),(int)(Caja.espesor+cm.getLocation().getY()+cm.getSize().getHeight()));
        }catch(Exception ex){
        }
        this.getContentPane().add(c);
    }
    
    public static Ventana creo(String titulo){
        return new Ventana(titulo);
    }
    public static Ventana creo(String titulo, int ancho, int alto){
        return new Ventana(titulo, ancho, alto);
    }

    public void windowOpened(WindowEvent e) {
    }

    public void windowClosing(WindowEvent e) {
        System.exit(0);
    }

    public void windowClosed(WindowEvent e) {
        System.exit(0);
    }

    public void windowIconified(WindowEvent e) {
    }

    public void windowDeiconified(WindowEvent e) {
    }

    public void windowActivated(WindowEvent e) {
    }

    public void windowDeactivated(WindowEvent e) {
    }
    
}
